package com.lsa.letcode.the105.btFromPreorderInorder;

import static org.junit.Assert.assertTrue;

import java.io.IOException;

import org.junit.Test;

import com.google.common.primitives.Ints;
import com.lsa.letcode.common.LetCodeTestBase;
import com.lsa.letcode.common.TreeNode;
import com.lsa.letcode.common.TreeUtils;

public class BtFromPreorderInorderTest extends LetCodeTestBase {
	@Test
	public void test() throws Exception {
		test("oneNode.tgf");
		test("test1.tgf");
		test("test2.tgf");
	}

	private void test(String resName) throws IOException {
		TreeNode tgfRoot = TreeUtils.fromTgf(this.getClass(), resName);
		Solution s = new Solution();
//		System.out.println(s.preorder(n));
//		System.out.println(s.inorder(n));
		TreeNode reconstructedRoot = s.buildTree(Ints.toArray(s.preorder(tgfRoot)), Ints.toArray(s.inorder(tgfRoot)));
		assertTrue(TreeUtils.areEqual(tgfRoot, reconstructedRoot));
//		File f = new File("data/iview/com/lsa/letcode/the105/btFromPreorderInorder/test.tgf");
//		System.out.println(f.getAbsolutePath());
//		TreeUtils.toTgf(reconstructedRoot, f);
	}
}
